import random

bank_name = "中国工商银行"
print('*********************************')
print('*     中国工商银行               *')
print("*********************************")
print("|   1、开户                      |")
print("|   2、存钱                      |")
print("|   3、取钱                      |")
print("|   4、转账                      |")
print("|   5、查询                      |")
print("|   6、再见                      |")
print("*********************************")
# bank={}
bank = {45234580: {'account': "天", 'password': 123456, 'country': '中国', 'province': '台湾', 'street': '台湾的街道',
                   'door': '台湾的门', 'money': 0, 'bank_name': '中国工商银行'},
        12345678: {'account': "韩", 'password': 123456, 'country': '中国', 'province': '台湾', 'street': '台湾的街道',
                   'door': '台湾的门', 'money': 0, 'bank_name': '中国工商银行'},
        23456789: {'account': "邓", 'password': 123456, 'country': '中国', 'province': '台湾', 'street': '台湾的街道',
                   'door': '台湾的门', 'money': 0, 'bank_name': '中国工商银行'}
        }


def adduser():
    account = random.randint(10000000, 99999999)
    username = input("请输入您用户名：")
    password = int(input("请输入您的密码："))
    country = input("\t\t请输入您的国家：")
    province = input("\t\t请输入您的省份：")
    street = input("\t\t请输入您的街道：")
    door = input("\t\t请输入您的门牌号：")
    a = addbank(account, username, password, country, province, street, door)
    if a == 1:
        print("开户成功,以下是您的详细信息")
        info = '''
                =========中国工商银行=======
                    1、账户%s
                    2、用户名%s
                    3、密码%s
                    4、国家%s
                    5、省份%s
                    6、街道%s
                    7、门牌号%s
                    8、金钱%s
        '''
        print(info % (account, username, password, country, province, street, door, bank[account]["money"]))
    elif a == 2:
        print("重名")
    elif a == 3:
        print("已满")


def addbank(account, username, password, country, province, street, door):
    if len(bank) >= 100:
        return 3
    elif username in bank:
        return 2
    else:
        bank[account] = {
            "username": username,
            "password": password,
            "country": country,
            "province": province,
            "street": street,
            "door": door,
            "money": 0,
            "bank_name": bank_name
        }
        return 1


# 存钱登录
def login():
    print(bank.keys())
    username_login = int(input("请输入账户:"))
    if username_login in bank.keys():
        money_login = int(input("请输入存钱的金钱:"))
        bank[username_login]["money"] = bank[username_login]["money"] + money_login
        print("您存的金额为:", bank[username_login]["money"])
        return True
    else:
        print("该账户不存在")
        return False


# 取钱
def cancel():
    name_cancel = cancel_dic()
    if name_cancel == 1:
        print("输入的用户名不存在")
    elif name_cancel == 2:
        print("输入的密码不正确")
    elif name_cancel == 3:
        print("当前余额不足")
    elif name_cancel == 0:
        print("取钱成功")


def cancel_dic():
    username_cancel = int(input("请输入您取钱的账户"))
    if username_cancel not in bank.keys():
        return 1
    else:
        password_cancel = int(input("请输入您的密码："))
        if password_cancel != bank[username_cancel]["password"]:
            return 2
        else:
            money_cancel = int(input("请输入取钱的金额："))
            if bank[username_cancel]["money"] < money_cancel:
                return 3
            else:
                bank[username_cancel]["money"] = bank[username_cancel]["money"] - money_cancel
                print("剩余的金额为:", bank[username_cancel]["money"])
                return 0


# 转账
def turn_money_num():
    turn_money_1 = turn_money()
    if turn_money_1 == 1:
        print("转出或转入的账户不存在")
    elif turn_money_1 == 2:
        print("转出账户的密码不正确")
    elif turn_money_1 == 3:
        print("转出账户余额不足")
    elif turn_money_1 == 0:
        print("转账成功")


def turn_money():
    turn_money_dic1 = 0  # 转入的金额
    turn_username = int(input("请输入转出账户："))
    turn_username1 = int(input("请输入转入账户："))
    if turn_username not in bank.keys() or turn_username1 not in bank.keys():
        return 1
    else:
        turn_password = int(input("请输入转出的账户密码："))
        if turn_password != bank[turn_username]["password"]:
            return 2
        else:
            turn_money_dic = int(input("请输入转出的金额："))
            if turn_money_dic > bank[turn_username]["money"]:
                return 3
            else:
                bank[turn_username]["money"] = bank[turn_username]["money"] - turn_money_dic
                turn_money_dic1 = turn_money_dic1 + turn_money_dic
                print("您的余额还剩", bank[turn_username]["money"])
                print("转入账户的余额", turn_money_dic1)
                return 0


# 查询
def inquire():
    inquire_username = int(input("请输入要查询的账户:"))
    if inquire_username not in bank.keys():
        print("该用户名不存在")
    else:
        inquire_password = int(input("请输入账户密码:"))
        if inquire_password != bank[inquire_username]["password"]:
            print("密码不正确")
        else:
            print("账户:", inquire_username, "密码:", inquire_password, "余额:", bank[inquire_username]["money"])


while True:
    o = input("请选择业务:")
    if o == "1":
        print("1、开户")
        adduser()
    elif o == "2":
        print("2、存钱")
        login()
    elif o == "3":
        print("3、取钱")
        cancel()
    elif o == "4":
        print("4、转账")
        turn_money_num()
    elif o == "5":
        print("5、查询")
        inquire()
    elif o == "6":
        print("6、再见")
        break
